<?php
//日本語
class Icon extends AppModel {

	var $name = 'Icon';
	var $recursive = -1;
	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $hasMany = array(
			'User' => array('className' => 'User',
								'foreignKey' => 'icon_id',
								'dependent' => false,
								'conditions' => '',
								'fields' => '',
								'order' => '',
								'limit' => '',
								'offset' => '',
								'exclusive' => '',
								'finderQuery' => '',
								'counterQuery' => ''
			)
	);
	//バリデート
	var $validate = array(
		'status' => array(
			'rule' => array('isInArray', array('notActive', 'active', 'resign', 'disable')),
		),
		'name' => array(
			'rule' => array('custom', '`^[a-zA-Z0-9_]*$`i'),
			'message' => 'ファイル名に使える文字外',
		),
		'ext' => array(
			'rule' => array('custom', '`^[a-zA-Z0-9_]*$`i'),
			'message' => '拡張子名に使える文字外',
		),
	);
	
	function getRandomNum()
	{
		$ids = $this->findAll(null, 'id', null, null, 1, -1);
		if(!$ids){return false;}
		foreach($ids as $value1){
			foreach($value1 as $value2){
				foreach($value2 as $value3){
					$array[$value3] = 1;
				}
			}
		}
		return (int)array_rand($array);
	}
	
	function isExistIcon($iconID)
	{
		return (bool)$this->field('id', array('id' => '= '.$iconID));
	}

}
?>